%
% pca.m
% (c) Neil Gershenfeld  12/23/97
% PCA example
%
clear all
eps = 1e-10;
npts = 100000;
x(:,1) = randn(npts,1);
x(:,2) = randn(npts,1);
x(:,3) = x(:,1)+x(:,2);
Cx = cov(x);
fprintf('covariance of x:\n')
fprintf('  %f %f %f\n',Cx)
[M,Ex] = eig(Cx);
fprintf('eigenvalues of covariance of x:\n')
fprintf('  %f %f %f\n',Ex)
M = M';
index = (diag(Ex) > eps);
M = M(index,:);
y = (M*x')';
Cy = cov(y);
fprintf('measured covariance of y:\n')
fprintf('  %f %f\n',cov(y))

